package com.likerSai;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 数字转罗马数字
 *
 * @author sun.ye
 * @since 2021-05-26 20:04
 */
public class IntToRoman {

    public static void main(String[] args) {
        String result = intToRoman(1994);
        System.out.println(result);
    }


    public static String intToRoman(int num){

        Map<String, Integer> dictionary = new LinkedHashMap<>();
        dictionary.put("M" ,1000);
        dictionary.put("CM",900);
        dictionary.put("D" ,500);
        dictionary.put("CD",400);
        dictionary.put("C" ,100);
        dictionary.put("XC",90);
        dictionary.put("L" ,50);
        dictionary.put("XL",40);
        dictionary.put("X" ,10);
        dictionary.put("IX",9);
        dictionary.put("V" ,5);
        dictionary.put("IV",4);
        dictionary.put("I",1);
        StringBuilder sb = new StringBuilder();

        for (Map.Entry<String, Integer> item : dictionary.entrySet()) {
            while (num >= item.getValue()) {
                sb.append(item.getKey());
                num -= item.getValue();
            }
        }
        return sb.toString();
    }
}